package com.wsx.seven.a;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Main0008 {

    public static void main(String[] args) {
        int[] array = new int[]{1, 6, 3, 9, 5, 10, 7, 8};
        tongSort(array);
    }

    public static void tongSort(int[] array) {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for (int i = 0; i < array.length; i++) {
            max = Math.max(max, array[i]);
            min = Math.min(min, array[i]);
        }

        int bucketNum = (max - min) / array.length + 1;
        ArrayList<ArrayList<Integer>> result = new ArrayList<>();
        for (int i = 0; i < bucketNum; i++) {
            result.add(new ArrayList<>());
        }

        for (int i = 0; i < array.length; i++) {
            int num = (array[i] - min) / array.length;
            result.get(num).add(array[i]);
        }
        for (int i = 0; i < result.size(); i++) {
            Collections.sort(result.get(i));
        }
        System.out.println(result.toString());;
    }

}
